package com.atguigu.vodTest;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.List;

/**
 * @Auther: fangshicai
 * @Date: 2022/2/25 12:05
 * @Description:
 */
public class GetPlayInfoById {

    /*获取播放地址函数*/
    public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
        //request创建
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        request.setVideoId("a8aca4f5b4ac4feaacfa91575a8fa3bf");
        return client.getAcsResponse(request);
    }

    /*以下为调用示例*/
    public static void main(String[] argv)  throws Exception{
        //1.创建初始化对象 传入我们自己的阿里云oos id和密钥
        DefaultAcsClient client = InitObject.initVodClient("LTAI5tEniNsPAs3eZmGoYSxy","1xHs1rP7kCOYsFZn8pdaCNW9ZeFGFh");

        //2.创建response和request
        //然后可根据response来获取未加密的地址
        GetPlayInfoResponse response = new GetPlayInfoResponse();
        try {
            response = getPlayInfo(client);
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            }
            //Base信息
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }
}
